home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Table / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  14.4 KB  |  546 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 3 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef SELECTION_H
  27. #include "Selection.h"
  28. #endif
  29.  
  30. #ifndef TRACKER_H
  31. #include "Tracker.h"
  32. #endif
  33.  
  34. #ifndef COMMANDS_H
  35. #include "Commands.h"
  36. #endif
  37.  
  38. #ifndef LINKING_H
  39. #include "Linking.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. #ifndef VIEW_H
  47. #include "View.h"
  48. #endif
  49.  
  50. // ----- Framework Layer -----
  51.  
  52. #ifndef FWFCTCLP_H
  53. #include "FWFctClp.h"
  54. #endif
  55.  
  56. #ifndef FWCLPCMD_H
  57. #include "FWClpCmd.h"
  58. #endif
  59.  
  60. #ifndef FWPROXY_H
  61. #include "FWProxy.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWITERS_H
  69. #include "FWIters.h"
  70. #endif
  71.  
  72. #ifndef FWLNKITE_H
  73. #include "FWLnkIte.h"
  74. #endif
  75.  
  76. #ifndef FWGROWBX_H
  77. #include "FWGrowBx.h"
  78. #endif
  79.  
  80. #ifndef FWSCLBAR_H
  81. #include "FWSclBar.h"
  82. #endif
  83.  
  84. // ----- OS Layer -----
  85.  
  86. #ifndef FWEVENT_H
  87. #include "FWEvent.h"
  88. #endif
  89.  
  90. #ifndef FWMNUBAR_H
  91. #include "FWMnuBar.h"
  92. #endif
  93.  
  94. #ifndef FWPOINT_H
  95. #include "FWPoint.h"
  96. #endif
  97.  
  98. #ifndef FWRECSHP_H
  99. #include "FWRecShp.h"
  100. #endif
  101.  
  102. #ifndef FWRECT_H
  103. #include "FWRect.h"
  104. #endif
  105.  
  106. #ifndef FWCFMRES_H
  107. #include "FWCFMRes.h"
  108. #endif
  109.  
  110. #ifndef FWRGNSHP_H
  111. #include "FWRgnShp.h"
  112. #endif
  113.  
  114. #ifndef FWODGEOM_H
  115. #include "FWODGeom.h"
  116. #endif
  117.  
  118. #ifndef FWCURSOR_H
  119. #include "FWCursor.h"
  120. #endif
  121.  
  122. #ifndef FWCONTXT_H
  123. #include "FWContxt.h"
  124. #endif
  125.  
  126. #ifndef FWEVEDEF_H
  127. #include "FWEveDef.h"
  128. #endif
  129.  
  130. // ----- Foundation Layer -----
  131.  
  132. #ifndef FWORDCOL_H
  133. #include "FWOrdCol.h"
  134. #endif
  135.  
  136. // ----- OpenDoc Includes -----
  137.  
  138. #ifndef SOM_ODClipboard_xh
  139. #include <Clipbd.xh>
  140. #endif
  141.  
  142. #ifndef SOM_ODDragItemIterator_xh
  143. #include <DgItmIt.xh>
  144. #endif
  145.  
  146. #ifndef SOM_ODDragAndDrop_xh
  147. #include <DragDrp.xh>
  148. #endif
  149.  
  150. #ifndef FWODTYPS_H
  151. #include "FWODTyps.h"
  152. #endif
  153.  
  154. #ifndef SOM_Module_OpenDoc_StdProps_defined
  155. #include <StdProps.xh>
  156. #endif
  157.  
  158. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  159. #include <StdTypes.xh>
  160. #endif
  161.  
  162. #ifndef SOM_ODStorageUnit_xh
  163. #include <StorageU.xh>
  164. #endif
  165.  
  166. #ifndef SOM_ODTransform_xh
  167. #include <Trnsform.xh>
  168. #endif
  169.  
  170. #ifndef SOM_ODSession_xh
  171. #include <ODSessn.xh>
  172. #endif
  173.  
  174. #ifndef SOM_ODDispatcher_xh
  175. #include <Disptch.xh>
  176. #endif
  177.  
  178. // ----- Macintosh Toolbox Includes -----
  179.  
  180. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  181. #include <Resources.h>
  182. #endif
  183.  
  184. //========================================================================================
  185. // RunTime Info
  186. //========================================================================================
  187.  
  188. #ifdef FW_BUILD_MAC
  189. #pragma segment odfTable
  190. #endif
  191.  
  192. FW_DEFINE_AUTO(CTableFrame)
  193.  
  194. //========================================================================================
  195. //    class CTableFrame
  196. //========================================================================================
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    CTableFrame::CTableFrame
  200. //----------------------------------------------------------------------------------------
  201.  
  202. CTableFrame::CTableFrame(Environment* ev, 
  203.                         ODFrame* odFrame, 
  204.                         FW_CPresentation* presentation, 
  205.                         CTablePart* tablePart,
  206.                         CTablePartContent* tableContent) :
  207.     FW_CEmbeddingFrame(ev, odFrame, presentation, tablePart),
  208.     FW_MDraggableFrame(ev, this),
  209.     FW_MDroppableFrame(ev, this),
  210.     fTablePart(tablePart),
  211.     fTableContent(tableContent)
  212. {
  213.     ChangeDroppableState(ev, FW_kFrameDroppable);
  214.     fDraggedCell.fX = fDraggedCell.fY = -1;
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //    CTableFrame::~CTableFrame
  219. //----------------------------------------------------------------------------------------
  220.  
  221. CTableFrame::~CTableFrame()
  222. {
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    CTableFrame::GetSelection
  227. //----------------------------------------------------------------------------------------
  228.  
  229. CTableSelection* CTableFrame::GetSelection(Environment* ev) const
  230. {
  231.     return (CTableSelection*)GetPresentation(ev)->GetSelection(ev);
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    CTableFrame::CanAcceptDrop
  236. //----------------------------------------------------------------------------------------
  237. // As an embedding frame I can accept anything
  238.  
  239. ODDragResult CTableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  240. {
  241. FW_UNUSED(ev);
  242. FW_UNUSED(dragInfo);
  243.     return TRUE;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    CTableFrame::DoVirtualKeyDown
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_Handled CTableFrame::DoVirtualKeyDown(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  251. {
  252.     FW_Handled    wasHandled = FW_kNotHandled;
  253.     CCell        cell = this->GetSelection(ev)->GetSelectedCell();
  254.     CCell        size = fTableContent->GetMaxRowCol();
  255.     
  256.     switch (theVirtualKeyEvent.GetKeyCode(ev))
  257.     {
  258.         case FW_kVKLeft:
  259.             if(cell.fX > 0)
  260.             {
  261.                 cell.fX -= 1;
  262.                 this->SelectCell(ev, cell);
  263.                 wasHandled = FW_kHandled;
  264.             }
  265.             break;
  266.         case FW_kVKRight:
  267.             if(cell.fX < size.fX - 1)
  268.             {
  269.                 cell.fX += 1;
  270.                 this->SelectCell(ev, cell);
  271.                 wasHandled = FW_kHandled;
  272.             }
  273.             break;
  274.         case FW_kVKUp:
  275.             if(cell.fY > 0)
  276.             {
  277.                 cell.fY -= 1;
  278.                 this->SelectCell(ev, cell);
  279.                 wasHandled = FW_kHandled;
  280.             }
  281.             break;
  282.         case FW_kVKDown:
  283.             if(cell.fY < size.fY - 1)
  284.             {
  285.                 cell.fY += 1;
  286.                 this->SelectCell(ev, cell);
  287.                 wasHandled = FW_kHandled;
  288.             }
  289.             break;
  290.  
  291.         case FW_kVKBackspace:
  292.         case FW_kVKClear:
  293.             FW_CClipboardCommand* cmd = this->NewClipboardCommand(ev, kODCommandClear);
  294.             if (cmd)
  295.             {
  296.                 cmd->Execute(ev);
  297.                 wasHandled = FW_kHandled;
  298.             }
  299.             break;
  300.     }
  301.  
  302.     return wasHandled;
  303. }
  304.     
  305. //----------------------------------------------------------------------------------------
  306. //    CTableFrame::DoMouseDownInEmbeddedFrameBorder
  307. //----------------------------------------------------------------------------------------
  308.  
  309. FW_Handled CTableFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  310. {
  311.     FW_Handled result = FW_kNotHandled;
  312.     
  313.     CTableView* tableView = this->GetTableView(ev);
  314.     FW_ASSERT(tableView != NULL);
  315.     
  316.     if (tableView->IsGridShown(ev) && this->Drag(ev, theBorderMouseEvent))
  317.     {
  318.         FW_gClosedHandCursor.Select();
  319.         result = FW_kHandled;
  320.     }
  321.     
  322.     return result;
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    CTableFrame::SelectCell
  327. //----------------------------------------------------------------------------------------
  328.  
  329. void CTableFrame::SelectCell(Environment* ev, const CCell& cell)
  330. {
  331.     GetSelection(ev)->Select(ev, cell);
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. // CTableFrame::GetContentRect
  336. //----------------------------------------------------------------------------------------
  337.  
  338. FW_CRect CTableFrame::GetContentRect(Environment* ev) const
  339. {
  340.     FW_CRect contentRect = GetBounds(ev);
  341.  
  342.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  343.     
  344.     contentRect.bottom -= sbSize.y;
  345.     contentRect.right -= sbSize.x;
  346.     
  347.     return contentRect;
  348. }
  349.  
  350. //----------------------------------------------------------------------------------------
  351. //    CTableFrame::Drag
  352. //----------------------------------------------------------------------------------------
  353.  
  354. FW_Handled CTableFrame::Drag(Environment* ev, const FW_CMouseEvent& event)
  355. {
  356.     fDraggedCell = GetSelection(ev)->GetSelectedCell();
  357.     
  358.     FW_Boolean result = FW_MDraggableFrame::Drag(ev, event);
  359.     
  360.     fDraggedCell.fX = fDraggedCell.fY = -1;
  361.     
  362.     return result;
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. //    CTableFrame::FocusStateChanged
  367. //----------------------------------------------------------------------------------------
  368.  
  369. void CTableFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  370. {    
  371.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  372.  
  373.     if (focus == FW_CPart::fgSelectionFocusToken)
  374.     {
  375.         CTableView* tableView = this->GetTableView(ev);
  376.         
  377.         if (tableView != NULL)
  378.             tableView->ChangeHighlightState(ev, newState ? kODFullHighlight : kODDimHighlight);
  379.             
  380.         CTableProxy* proxy = GetSelection(ev)->GetSelectedProxy();
  381.         if (proxy)
  382.             proxy->SetSelectState(ev, newState);
  383.     }
  384. }
  385.  
  386. //----------------------------------------------------------------------------------------
  387. //    CTableFrame::NewDropCommand
  388. //----------------------------------------------------------------------------------------
  389.  
  390. FW_CDropCommand* CTableFrame::NewDropCommand(Environment* ev,
  391.                                             FW_CFrame* frame,
  392.                                             ODDragItemIterator* dropInfo, 
  393.                                             ODFacet* odFacet, 
  394.                                             const FW_CPoint& dropPoint)
  395. {
  396. FW_UNUSED(frame);
  397.     FW_ASSERT(frame == this);
  398.     
  399.     CCell dropCell;
  400.     ETableLoc loc = fTableContent->HitTest(ev, dropPoint, dropCell);
  401.  
  402.     if (loc != kTLCell || dropCell == fDraggedCell || fTableContent->CellToProxy(dropCell) != NULL)    // If alreay a proxy gave up
  403.         return NULL;
  404.     else
  405.         return FW_NEW(CCellDropCommand, (ev, fTablePart, fTableContent, this,
  406.                                          dropInfo, odFacet, dropPoint,
  407.                                         dropCell, fDraggedCell));
  408. }
  409.  
  410. //----------------------------------------------------------------------------------------
  411. //    CTableFrame::NewDropTracker
  412. //----------------------------------------------------------------------------------------
  413.  
  414. FW_CDropTracker* CTableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  415. {
  416.     return new CTableDropTracker(ev, fTablePart, fTableContent, (CTableView*)view, facet, fDraggedCell);
  417. }
  418.  
  419. //----------------------------------------------------------------------------------------
  420. // CTableFrame::NewClipboardCommand
  421. //----------------------------------------------------------------------------------------
  422.  
  423. FW_CClipboardCommand* CTableFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  424. {
  425.     return FW_NEW(CTableEditCommand, (ev,
  426.                                       commandID,
  427.                                       fTablePart,
  428.                                       fTableContent,
  429.                                       this,
  430.                                       this->GetSelection(ev)));
  431. }
  432.  
  433. //----------------------------------------------------------------------------------------
  434. // CTableFrame::NewDragCommand
  435. //----------------------------------------------------------------------------------------
  436.  
  437. FW_CDragCommand* CTableFrame::NewDragCommand(Environment* ev, 
  438.                                              FW_CFrame* theFrame,
  439.                                              const FW_CMouseEvent& theMouseEvent)
  440. {
  441. FW_UNUSED(theMouseEvent);
  442.     return FW_NEW(CCellDragCommand, (ev, fTableContent, theFrame, this->GetSelection(ev)));
  443. }
  444.  
  445. //----------------------------------------------------------------------------------------
  446. //    CTableFrame::NewInsertCommand
  447. //----------------------------------------------------------------------------------------
  448. FW_CInsertCommand* CTableFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  449. {
  450.     return FW_NEW(CTableInsertCommand, (ev,
  451.                                         this,
  452.                                         fileSpec,
  453.                                         fTablePart,
  454.                                         GetSelection(ev)->GetSelectedCell()));
  455. }
  456.  
  457. //----------------------------------------------------------------------------------------
  458. // CTableFrame::MoveProxy
  459. //----------------------------------------------------------------------------------------
  460.  
  461. void CTableFrame::MoveProxy(Environment* ev, CTableProxy* proxy, const CCell& destCell)
  462. {
  463.     // Invalidate the source cell
  464.     FW_CRect rect;
  465.     CCell srcCell = proxy->GetCell();
  466.     fTableContent->FindRect(srcCell, rect);
  467.     this->GetPresentation(ev)->Invalidate(ev, rect);
  468.  
  469.     proxy->MoveEmbeddedFrames(ev, destCell);
  470.     proxy->SetCell(destCell);
  471.     this->SelectCell(ev, destCell);
  472.  
  473.     // Invalidate the destination cell
  474.     fTableContent->FindRect(destCell, rect);
  475.     this->GetPresentation(ev)->Invalidate(ev, rect);
  476.  
  477. }
  478.  
  479. //---------------------------------------------------------------------------------------
  480. //    CTableFrame::FacetAdded
  481. //---------------------------------------------------------------------------------------
  482.  
  483. void CTableFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  484. {
  485.     FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount);    // call inherited
  486.  
  487.     if (facetCount == 1)
  488.         fTablePart->DoPostCreate(ev);
  489. }
  490.  
  491. //----------------------------------------------------------------------------------------
  492. //    CTableFrame::PostCreateViewFromStream
  493. //----------------------------------------------------------------------------------------
  494. // PostCreateViewFromStream is called after subviews are created from resources.  
  495. // Add code which cannot be handled by current resource types.
  496.  
  497. void CTableFrame::PostCreateViewFromStream(Environment*)
  498. {
  499.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  500.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  501.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);    
  502.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);    
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. // CTableFrame::FrameShapeChanged
  507. //----------------------------------------------------------------------------------------
  508. //    My content view size has changed I need to clip my embedded facets.
  509.  
  510. void CTableFrame::FrameShapeChanged(Environment* ev)
  511. {
  512.     FW_CEmbeddingFrame::FrameShapeChanged(ev);
  513.     
  514.     FW_CFacetClipper facetClipper;
  515.     facetClipper.Clip(ev, this);
  516. }
  517.  
  518. //----------------------------------------------------------------------------------------
  519. // CTableFrame::AdjustZoomedWindowSize
  520. //----------------------------------------------------------------------------------------
  521. //    proposedSize is the interior size of the window
  522.  
  523. void CTableFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
  524. {
  525. FW_UNUSED(ev);
  526.     proposedSize = GetContentView(ev)->GetExtent(ev) + FW_CScrollBar::GetDefaultScrollBarSize();
  527. }
  528.  
  529. //----------------------------------------------------------------------------------------
  530. // CTableFrame::AdjustContentViewSize
  531. //----------------------------------------------------------------------------------------
  532.  
  533. void CTableFrame::AdjustContentViewSize(Environment* ev, FW_ERedrawVerb redraw)
  534. {
  535.     FW_CRect contentRect = GetContentRect(ev);    
  536.  
  537.     FW_CPoint drawingSize = fTableContent->GetExtent();
  538.     
  539.     FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
  540.                             FW_Minimum(drawingSize.y, contentRect.Height()));
  541.  
  542.     FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
  543.     if (currentSize != drawViewSize)
  544.         GetContentView(ev)->SetSize(ev, drawViewSize, redraw);
  545. }
  546.